package codepulse.blogmoon.cn.system.config;

import codepulse.blogmoon.cn.common.entity.Result;
import codepulse.blogmoon.cn.common.enums.ErrorCode;
import codepulse.blogmoon.cn.common.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class RestExceptionConfig {

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
      log.error("system error",e);
        return Result.error(ErrorCode.SYSTEM_ERROR.getMsg());
    }

    @ExceptionHandler(BizException.class)
    public Result bizException(BizException e) {

        log.error("system error",e);
        return Result.result(e.getCode(), e.getMsg(), false);
    }


}
